#include <iostream>
#include <algorithm>
using namespace std;
int ret=0x3f3f3f;


int main()
{
	string str;
	cin>>str;
	for(char c='a';c<='z';c++)
	{
		int cnt=0;
		for(auto& t:str)
		{
			cnt+=min(abs(t-c),26-(abs(t-c)));
		}
		ret=min(ret,cnt);
	}
	cout<<ret<<endl;
	return 0;
}
